<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>修改网站信息</title>
    <link href="../../css/admin/style.css" rel="stylesheet" type="text/css" />
    <script src="../../js/jquery-1.8.3.min.js" type="text/javascript"></script >
    <script src="../../js/ajaxfileupload.js" type="text/javascript"></script>
    <script>
        $(function (){
            $.get("../../company/getwebmsg",function (res){
                console.log(res);
                var imgsrc =  "http://127.0.0.1:8080/userImg/companyLogo/"+res.data.logoname;
                $("#webname").val(res.data.webname);
                $("#logo").attr("src",imgsrc);
                $("#logoname").val(res.data.logoname);
                $("#recordnum").val(res.data.recordnum);
                $("#phone").val(res.data.phone);
                $("#companyname").val(res.data.companyname);
            },"json")
        })
        function savecom(){
            $.post("../../company/savewebmsg",$("#formId").serialize(),function(res){
                if (res.code == 202){
                    window.parent.location.replace("../login.html");
                }else if (res.code == 500){
                    alert(res.msg);
                }else {
                    alert(res.msg);
                    location.replace("list.html");
                }
            })
        }

        function fileUpload(){
            $.ajaxFileUpload({
                    url: '../../company/fileUpload', //用于文件上传的服务器端请求地址  调用后端接口(interface)
                    fileElementId: 'fileID', //文件上传域的ID
                    dataType: 'json', //返回值类型 一般设置为json
                    success: function (data){
                        if (data.code ==200){
                            var imgsrc = "http://localhost:8080/userImg/companyLogo/"+data.data;
                            $("#logo").attr("src",imgsrc);
                            $("#logoname").val(data.data);
                        }else if (data.code = 500){
                            console.log(data.msg);
                        }
                    }
                }
            )
        }
    </script>
</head>
<body>
<form id="formId">
    <input type="hidden" id="adminid" name="id"/>
    <div class="formbody">
        <div class="formtitle"><span>基本信息</span></div>
        <ul class="forminfo">
            <li>
                <label>网站名</label>
                <input id="webname" name="webname" type="text" class="dfinput" />
            </li>
            <li>
                <label>logo</label>
                <img id="logo" src='' width='30' height='30'/>
                更换头像<input type="file" name="fileName" accept=".jpg,.png,.gif" id="fileID">
                <input type="button" value="上传" onclick="fileUpload()">
                <input type="hidden" id="logoname" name="logoname" value="">
            </li>
            <li>
                <label>备案号</label>
                <input id="recordnum" name="recordnum" type="text" class="dfinput" />
            </li>
            <li>
                <label>联系方式</label>
                <input id="phone" name="phone" type="text" class="dfinput" />
            </li>
            <li>
                <label>公司名字</label>
                <input id="companyname" name="companyname" type="text" class="dfinput" />
            </li>

            <li>
                <input type="button" value="保存" onclick="savecom()">
            </li>
        </ul>
    </div>

</form>
</body>
</html>